﻿//======================================================
//==     (c)2013  OpenLayers.cn inc by 飞龙在天 v1.0  ==
//==          Forum:bbs.OpenLayers.cn                 ==
//==         Website:www.OpenLayers.cn                ==
//== 开源旗舰版见 淘宝: http://giscenter.taobao.com   ==
//======================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
 

namespace Common
{
    public class TileServer
    {

        public static string GOOGLE_SATELLITE_URL = System.Configuration.ConfigurationSettings.AppSettings["GOOGLE_SATELLITE_URL"].ToString();
        public static string GOOGLE_ROAD_URL = System.Configuration.ConfigurationSettings.AppSettings["GOOGLE_ROAD_URL"].ToString();

        public static string GOOGLE_Terrain_URL = System.Configuration.ConfigurationSettings.AppSettings["GOOGLE_Terrain_URL"].ToString();



        public static string getTileUrl(string tileName, int zoom, Int64 col, Int64 row)
        {
          
            switch (tileName.ToUpper())
            {
                case "GOOGLE_ROADMAP":
                    return GoogleRoadTile(zoom, col, row);

                case "GOOGLE_SATELLITE":
                    return GoogleSatelliteTile(zoom, col, row);
                case "GOOGLE_TERRAIN":
                    return GetTileUrl(zoom, col, row,GOOGLE_Terrain_URL);

              
            }
            return GoogleRoadTile(zoom, col, row);
        }


        private static string GetTileUrl(int zoom, Int64 col, Int64 row, string downUrl)
        {
            Random random = new Random(4);
            return string.Format(downUrl, new object[] { zoom, col, row, random.Next(4) });
        }


        private static string GoogleSatelliteTile(int zoom, Int64 col, Int64 row)
        {
            Random random = new Random(4);
            return string.Format(GOOGLE_SATELLITE_URL, new object[] { zoom, col, row, random.Next(4) });
        }

        private static string GoogleRoadTile(int zoom, Int64 col, Int64 row)
        {
            Random random = new Random(4);
            return string.Format(GOOGLE_ROAD_URL, new object[] { zoom, col, row, random.Next(4) });
        }



        
    }
}

